Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports System.Collections.Generic
Imports facebook.Schema
Imports FBMLSample.controls
Imports System.Web.Configuration
Imports facebook.web

Namespace FBMLSample
	Partial Public Class Home
		Inherits BasePage
		Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As EventArgs)
			Master.RequireLogin = True
			Master.SetSelectedTab("home")

		End Sub
		Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
			' You need to set info or profile box in order for the buttons on the page to show up.
			' Don't set them every time.
			Dim pref = Me.Master.API.data.getUserPreference(1)
			If pref IsNot "set" Then
				Me.Master.API.profile.setInfo("My Smiles", 5, getSampleInfo(), Me.Master.API.uid)
				Me.Master.API.profile.setFBML(Me.Master.API.uid, Nothing, getUserProfileBox(), Nothing)
				Me.Master.API.data.setUserPreference(1, "set")
			End If
		End Sub

		Private Function getSampleInfo() As List(Of info_field)
			Dim callback = WebConfigurationManager.AppSettings("Callback")
			Dim options = New List(Of info_item)()
			options.Add(New info_item With {.label = "Happy", .image = callback & "images/smile0.jpg", .sublabel = "", .description = "The original and still undefeated.", .link = "http://apps.facebook.com/" & Master.suffix & "/smile.aspx?smile=1"})
			options.Add(New info_item With {.label = "Indifferent", .image = callback & "images/smile1.jpg", .sublabel = "", .description = "meh....", .link = "http://apps.facebook.com/" & Master.suffix & "/smile.aspx?smile=2"})
			options.Add(New info_item With {.label = "Sad", .image = callback & "images/smile2.jpg", .sublabel = "", .description = "Oh my god! you killed my dog!", .link = "http://apps.facebook.com/" & Master.suffix & "/smile.aspx?smile=3"})
			options.Add(New info_item With {.label = "Cool", .image = callback & "images/smile3.jpg", .sublabel = "", .description = "Yeah. whatever", .link = "http://apps.facebook.com/" & Master.suffix & "/smile.aspx?smile=4"})

			Dim field = New info_field()
			field.field = "Good Smilies"
			field.items = New info_field.itemsLocalType()
			field.items.info_item = options

            Dim sampleInfo = New List(Of info_field)
            sampleInfo.Add(field)
            Return sampleInfo
        End Function

		Private Function getUserProfileBox() As String
			Return FBMLControlRenderer.RenderFBML(Of String)(String.Format("~/controls/{0}.ascx", GetType(ProfileBox).Name), Master.suffix)
		End Function
	End Class
End Namespace
